<template>
  <div class="common-handle">
    <el-form ref="form" :model="form" label-position="left" :inline="true">
      <!-- 用户列表查询条件 -->
      <el-form-item v-if="moduleName === 'userList'" label="学号" prop="userName">
        <el-input v-model="form.userName" clearable />
      </el-form-item>
      <!-- 操作日志查询条件 -->
      <el-form-item v-if="moduleName === 'userLog'" label="用户名称" prop="handleUserName">
        <el-input v-model="form.handleUserName" clearable />
      </el-form-item>
      <el-form-item v-if="moduleName === 'userLog'" label="操作名称" prop="handleName">
        <el-input v-model="form.handleName" clearable />
      </el-form-item>
      <el-form-item v-if="moduleName === 'userList' || moduleName==='financeList'" label="姓名" prop="nickName">
        <el-input v-model="form.nickName" clearable />
      </el-form-item>
      <!-- 角色列表查询条件 -->
      <el-form-item v-if="moduleName === 'roleList'" label="角色名称" prop="roleName">
        <el-input v-model="form.roleName" clearable />
      </el-form-item>
      <!-- 权限组查询条件 -->
      <el-form-item v-if="moduleName === 'permissionGroupList'" label="权限组名称" prop="permissionGroupName">
        <el-input v-model="form.permissionGroupName" clearable />
      </el-form-item>
      <!-- 学院配置 -->
      <el-form-item v-if="moduleName === 'professionConfig' || moduleName ==='academyConfig' " label="学院名称" prop="academyName">
        <el-input v-model="form.academyName" clearable />
      </el-form-item>
      <!-- 专业配置 -->
      <el-form-item v-if="moduleName === 'professionConfig' || moduleName ==='classRoomList' " label="专业名称" prop="professionName">
        <el-input v-model="form.professionName" clearable />
      </el-form-item>
      <!-- 宿舍配置 -->
      <el-form-item v-if="moduleName === 'roomList' || moduleName ==='dormitoryConfig'" label="楼幢" prop="building">
        <el-input v-model="form.building" clearable />
      </el-form-item>
      <el-form-item v-if="moduleName === 'dormitoryConfig'" label="楼长名称" prop="dormitoryManagerName">
        <el-input v-model="form.dormitoryManagerName" clearable />
      </el-form-item>

      <!-- 班级列表查询条件  -->
      <el-form-item v-if="moduleName === 'classRoomList'" label="班级年级" prop="classYear">
        <el-date-picker
          v-model="form.classYear"
          style="width:150px"
          type="year"
          placeholder="选择年"
          value-format="yyyy"
        />
      </el-form-item>
      <!-- 住宿列表查询条件 -->
      <el-form-item v-if="moduleName === 'roomList'" label="门牌号" prop="tablet">
        <el-input v-model="form.tablet" clearable />
      </el-form-item>
      <el-form-item v-if="moduleName === 'roomList'" label="是否空闲" prop="isFree">
        <el-checkbox v-model="form.isFree" />
      </el-form-item>
      <!-- 场景查询条件 -->
      <el-form-item v-if="moduleName === 'sceneList' || moduleName === 'sceneDist'" label="名称" prop="sceneName">
        <el-input v-model="form.sceneName" clearable />
      </el-form-item>
      <!-- 公共方法 -->
      <el-button type="primary" @click="searchData('search')">查询</el-button>
      <el-button v-if="moduleName !== 'userLog'" type="success" @click="clearSearch('clear')">清除</el-button>
    </el-form>
    <div class="button-group">
      <el-button v-if="moduleName !== 'userLog'" type="primary" @click="addData('add')">新增</el-button>
      <el-button v-if="moduleName !== 'userLog' && moduleName!=='userList'" type="danger" @click="deleteData('delete')">删除</el-button>
      <download-excel
        class="export-excel-wrapper"
        :data="exportExcelData"
        :fields="fields"
        :name="filename"
        type="xlsx"
      >
        <el-button type="primary">导出</el-button>
      </download-excel>
    </div>
  </div>
</template>

<script>

export default {
  name: 'CommonHandle',
  props: {
    moduleName: {
      type: String,
      default: ''
    },
    exportExcelData: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      filename: '',
      fields: {},
      form: {
        // 用户列表查询条件
        userName: '',
        nickName: '',
        // 日志查询条件
        handleUserName: '',
        handleName: '',
        // 角色列表查询条件
        roleName: '',
        // 权限组查询条件
        permissionGroupName: '',
        // 学院配置查询条件
        academyName: '',
        // 专业配置查询条件
        professionName: '',
        // 宿舍配置查询条件
        dormitoryManagerName: '',
        building: null,
        // 班级列表查询条件
        classYear: '',
        // 住宿列表查询条件
        floor: null,
        tablet: null,
        isFree: false,
        // 场景和距离查询条件
        sceneName: ''
      }
    }
  },
  watch: {
  },
  mounted() {
    if (this.moduleName === 'userList') {
      this.fields = {
        '学号': 'userName',
        '姓名': 'nickName',
        '性别': 'sex',
        '入学时间': 'admissionYear',
        '所属班级': 'classId',
        '宿舍': 'room',
        '民族': 'nationalityId',
        '出生省份': 'birthplaceId',
        '学制': 'academicYear',
        '学历': 'culturalLevelId',
        '是否支付学费': 'isPay'
      }
      this.filename = '用户列表'
    } else if (this.moduleName === 'userLog') {
      this.filename = '操作日志'
      this.fields = {
        '操作用户': 'handleUserId',
        '操作名称': 'handleName',
        '操作系统': 'osType',
        '客户端类型': 'clientType',
        '创建时间': 'createTime'
      }
    } else if (this.moduleName === 'roleList') {
      this.filename = '角色列表'
      this.fields = {
        '角色名称': 'roleName',
        '角色标识': 'roleCode',
        '管理标识': 'roleDesc'
      }
    } else if (this.moduleName === 'permissionGroupList') {
      this.filename = '权限组列表'
      this.fields = {
        '权限组名称': 'permissionGroupName',
        '权限组描述': 'permissionGroupDesc'
      }
    } else if (this.moduleName === 'academyConfig') {
      this.filename = '学院配置'
      this.fields = {
        '学院名称': 'academyName',
        '辅导员': 'counselorId',
        '院长': 'deanId',
        '副院长': 'associateDeanId',
        '创建时间': 'createTime',
        '更新时间': 'updateTime'
      }
    } else if (this.moduleName === 'professionConfig') {
      this.filename = '专业配置'
      this.fields = {
        '专业名称': 'professionName',
        '设立年份': 'professionBuildYear',
        '学院': 'academyId',
        '创建时间': 'createTime',
        '修改时间': 'updateTime'
      }
    } else if (this.moduleName === 'dormitoryConfig') {
      this.filename = '宿舍配置'
      this.fields = {
        '楼幢': 'building',
        '楼长': 'dormitoryManagerId',
        '联系电话': 'dormitoryManagerTel',
        '创建时间': 'createTime',
        '修改时间': 'updateTime'
      }
    } else if (this.moduleName === 'classRoomList') {
      this.filename = '班级管理'
      this.fields = {
        '年级': 'classYear',
        '专业': 'professionId',
        '班级': 'classCode',
        '班主任': 'classTeacherId',
        '创建时间': 'createTime',
        '修改时间': 'updateTime'
      }
    } else if (this.moduleName === 'financeList') {
      this.filename = '财务列表'
      this.fields = {
        '用户名称': 'userId',
        '订单名称': 'orderName',
        '订单价格': 'money',
        '订单描述': 'orderDesc'
      }
    } else if (this.moduleName === 'roomList') {
      this.filename = '住宿管理'
      this.fields = {
        '楼幢': 'building',
        '门牌号': 'tablet',
        '床号': 'bedNumber',
        '是否空闲': 'isFree',
        '创建时间': 'createTime',
        '修改时间': 'updateTime'
      }
    }
    console.log(this.exportExcelData, 'export')
  },
  methods: {
    searchData() {
      this.$emit('searchData', this.form)
    },
    clearSearch() {
      this.$refs['form'].resetFields()
      this.$emit('searchData', null)
    },
    addData() {
      this.$emit('addData')
    },
    deleteData() {
      this.$emit('deleteData')
    }
  }
}
</script>

<style lang="scss" scoped>
  .button-group {
    display: flex;
    .el-button {
      margin-right: 20px;
    }
  }
</style>
